package metadata

import "git.cloud.inspur.com/ichain/ichain-sdk-go/pkg/core/logging/api"

type ModuleLevels struct {
	levels map[string]api.Level
}

func (l *ModuleLevels) GetLevel(module string) api.Level {
	level, exists := l.levels[module]
	if !exists {
		level, exists = l.levels[""]
		if !exists {
			level = api.INFO
		}
	}
	return level
}

func (l *ModuleLevels) SetLevel(module string, level api.Level) {
	if l.levels == nil {
		l.levels = make(map[string]api.Level)
	}
	l.levels[module] = level
}

func (l *ModuleLevels) IsEnabledFor(module string, level api.Level) bool {
	return level <= l.GetLevel(module)
}
